package com.hand.endpoint;

import com.hand.dao.CountryRepository;
import com.hand.entity.GetCountryRequest;
import com.hand.entity.GetCountryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

/*******************Copyright Information************************
 *              AUTHOR: Lorin.Mitchell                           *
 *              DATE: 2017/11/6                                 *
 *              TIME: 19:39                                      * 
 ****************************************************************/
    //@Endpoint注解将该类标注为SOA的传入信息类
@Endpoint
public class CountryEndpoint {
    private static final String NAMESPACE_URI = "http://www.hand-china.com";

    @Autowired
    private CountryRepository countryRepository;


    //@PayloadRoot注解，表示该方法将处理以namespace和localPart的xml请求信息
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
    //@ResponsePayload注解，表示将返回值映射到reponse中
    @ResponsePayload
    public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) {
        GetCountryResponse response = new GetCountryResponse();
        response.setCountry(countryRepository.findCountry(request.getName()));

        return response;
    }

}
